#include <mat4.h>
#include <vec4.h>
#include <log.h>
#include <transform.h>
#include <utility_math.h>
#include <random_gen.h>

Mat4x4 createMatrix(Random<float>& r) {
    Mat4x4 mat;
    std::for_each(mat.begin(), mat.end(), [&r](float& x) { x = r(); });
    return mat;
}

void test_mat4_operator() {
    Random<float> random(10);

    Mat4x4 m1 = createMatrix(random);
    Mat4x4 m2 = createMatrix(random);

    log(m1, "m1:\n");
    log(m2, "m2:\n");
    log(transpose(m1), "transpose m1:\n");
    log(m1 + m2, "m1 + m2:\n");
    log(m1 - m2, "m1 - m2:\n");
    log(m1 * 2.0f, "m1 * 2:\n");
    log(m1 * m2, "m1 * m2:\n");
}

void test_transform() {
    float width = 800;
    float height = 720;

    Mat4x4 model = Mat4x4::One();
    model = translate(model, Vec3f{0.0f, 0.0f, -5.0f});
    log(model, "model:\n");

    Mat4x4 view = lookAt(Vec3f::Zero(), {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f, 0.0f});
    log(view, "view:\n");
    Mat4x4 proj = perspective(radians(60), width / height, 1.0f, 1000.0f);
    log(proj, "proj:\n");

    Vec4f p1{ 1.0f, 0.5f, -0.5f, 1.0f };
    log(proj* view * model * p1, "MVP:\n");
}

int main() {
    test_mat4_operator();
    test_transform();
    return 0;
}